package servlet;

import pojo.News;
import service.NewsService;
import service.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.InetAddress;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/11/10 21:48
 */
@WebServlet(name = "ReadServlet" ,urlPatterns = "/ReadServlet")
public class ReadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);






    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进来了");
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");

        Integer id = Integer.parseInt(request.getParameter("id"));
        Integer count = Integer.parseInt(request.getParameter("count"));
        count++;

        NewsService newsService = new NewsServiceImpl();
        newsService.updateViewCount(count,id);
        News news = newsService.selectOneById(id);
        request.setAttribute("news",news);

        request.getRequestDispatcher("news.jsp").forward(request,response);

    }
}
